package leetcode.每日一题.模拟;

import org.junit.Test;

/**
 * @author ：zsy
 * @date ：Created 2023/1/3 6:44 PM
 * @description：
 */
public class 检查句子中的数字是否递增 {
    @Test
    public void test() {
        System.out.println(new Solution().areNumbersAscending("hello world 5 x 5"));
    }

    class Solution {
        public boolean areNumbersAscending(String s) {
            int pos = 0;
            int prev = -1;
            int n = s.length();
            while (pos < n) {
                if (Character.isDigit(s.charAt(pos))) {
                    int cur = 0;
                    while (pos < n && Character.isDigit(s.charAt(pos))) {
                        cur = cur * 10 + s.charAt(pos) - '0';
                        pos++;
                    }
                    if (cur <= prev) {
                        return false;
                    }
                    prev = cur;
                } else {
                    pos++;
                }
            }
            return true;
        }
    }
}
